import { _decorator, Asset, Component, instantiate, JsonAsset, Node, Prefab, Vec3 } from 'cc';
import { Brick } from './Brick';
const { ccclass, property } = _decorator;

@ccclass('Bricks')
export class Bricks extends Component {
    @property(JsonAsset)
    js:JsonAsset = null
    @property(Prefab)
    brick:Prefab = null

    start() {
        console.log(this.js.json.level)
        let bricks:number[][] = this.js.json.level
        let brick:Node
        let pos = new Vec3
        for(let i = 0;i<bricks.length;i++){
            for(let j =0;j<bricks[i].length;j++){

                if(bricks[i][j] == 0){
                    
                }else{
                    pos.set(-450+(j*90),860-(i*50),0)
                    brick = instantiate(this.brick)
                    brick.getComponent(Brick).life = bricks[i][j]
                    this.node.addChild(brick)
                    brick.setPosition(pos)
                }
            }
        }
        
    }

    update(deltaTime: number) {
    }
}


